<template>
  <div>
    <div class="box">
      <div class="box-body">
        <el-row :gutter="20">
          <el-form :model="query" label-position="top">
            <el-col :span="6">
              <el-form-item label="关键字:">
                <el-input v-model="query.keyword" placeholder="ID/名称/简称/邮箱"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="分销商类型:">
                <el-select v-model="query.type" multiple clearable placeholder="选择分销商类型">
                  <el-option v-for="(value, key) in DtbType" :key="key" :label="value" :value="key"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="状态:">
                <el-select v-model="query.status" multiple clearable placeholder="选择分销商状态">
                  <el-option v-for="(value, key) in DtbStatus" :key="key" :label="value" :value="key"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="" class="no-top-label">
                <el-button type="primary" icon="search" @click="loadPage(1)">检索</el-button>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
    </div>

    <el-table :data="page.content" v-loading.body="loading" border>
      <el-table-column prop="id" label="ID" width="60" />
      <el-table-column prop="name" label="名称" />
      <el-table-column prop="shortName" label="简称" width="120" />
      <el-table-column prop="email" label="邮箱" width="200" />
      <el-table-column label="账户余额/信用额度/可用额度" width="240">
        <template slot-scope="scope">
          {{scope.row.balance.balance/100}}/{{scope.row.balance.credit/100}}/{{(scope.row.balance.balance+scope.row.balance.credit)/100}}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态" width="90" align="center">
        <template slot-scope="scope">
          <el-tag :type="['', 'primary', 'success', 'danger'][scope.row.status]">
            {{DtbStatus[scope.row.status]}}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="90" align="center">
        <template slot-scope="scope">
          <router-link :to="'/dtb/details?dtbId=' + scope.row.id">
            <el-button type="primary" size="small">详情</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <!-- pagination -->
    <el-pagination @current-change="showPage" :current-page.sync="page.page" :page-size="page.pageSize" :total="page.totalElements" layout="total, prev, pager, next, jumper" />
  </div>
</template>

<script>
import { Dtb } from '@/store/api'
import Pagination from '@/utils/pagination'
import * as Constants from '@/constants'
export default {
  data() {
    return {
      ...Constants,
      loading: true,
      balance: {},
      query: {
        type: ['1', '2'],
        status: ['1', '2']
      },
      page: {
        content: []
      }
    }
  },
  created() {
    this.loadPage(1)
  },
  methods: {
    ...Pagination,
    list(page, query) {
      this.loading = true
      return Dtb.list(query).then(data => {
        this.page = data
        this.loading = false
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 100%;
}

.display-form .display-item label {
  width: 100px;
}
</style>
